


#include <material_editor/materialview.h>
#include <material_editor/textureeditor.h>
#include <genericdeletedialog.h>
#include <genericrenamedialog.h>
#include <genericsavedialog.h>
#include <session.h>



void MaterialView::TextureEdit (Texture *texture)
{
  if (!OpenEditor(texture))
    {
      InsertEditor(new TextureEditor (texture));
    }
}



void MaterialView::TextureEditCurrent ()
{
  TextureItem* item = get_current_item<TextureItem>(_overview);
  if (!item)
    {
      return;
    }
  TextureEdit (item->GetTexture());
}



void MaterialView::TextureAdd()
{
  CategoryItem* item = get_current_item<CategoryItem>(_overview);
  if (!item)
    {
      return;
    }

  GenericRenameDialog dlg (Session::Get()->GetMainWindow());
  dlg.SetType("Create new texture", "");
  dlg.SetName("New Texture");
  dlg.SetCategory(item->GetCategory());
  if (dlg.exec() == QDialog::Rejected)
    {
      return;
    }


  _selectNewItems = true;
  Texture* texture = _manager->CreateTexture();
  texture->SetName(dlg.GetName());
  texture->SetCategory(dlg.GetCategory());

  if (_manager->AddTexture(texture))
    {
      TextureEdit(texture);
    }
  _selectNewItems = false;
}

void MaterialView::TextureAdded(Texture *texture)
{
  AddItem (new TextureItem(this, texture), texture);
}

void MaterialView::EditTexture(Texture *texture)
{
  TextureEdit(texture);
}
